import os
import dashscope

# 从环境变量中，获取 DASHSCOPE_API_KEY
api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.api_key = api_key

# 封装模型响应函数
def get_response(messages):
    response = dashscope.Generation.call(
        model='deepseek-v3',
        messages=messages,
        result_format='message'  # 将输出设置为message形式
    )
    return response
# 文章链接
review = 'https://xie.infoq.cn/article/2767e4ade5f4992b8da135f56?utm_source=home_write_related&utm_medium=article'
messages = [
    {"role": "system","content": "你是一名作文助手，帮我总结一下链接对应的文章内容，输出不少于150字"},
    {"role": "user", "content": review}
]

response = get_response(messages)
print(response.output.choices[0].message.content)